<template>
  <div>
    <el-popover v-if="hasLiveAuth" v-model="livePopoverVisible" width="170" popper-class="custom-tab-popover">
      <el-checkbox-group v-model="liveCheckedList" class="filter-checkbox-group" text-color="#fd3264" fill="#fd3264">
        <div class="el-checkbox">
          <span v-if="!liveCheckedList.length" class="check-box-btn active">
            <span class="check-box-style"/><span class="el-checkbox__label">全部</span>
          </span>
          <span v-else class="check-box-btn" @click.stop="cancelLiveSelected">
            <span class="check-box-style"/><span class="el-checkbox__label">全部</span>
          </span>
        </div>
        <el-checkbox v-for="platform in livePlatformList" :key="platform.key" :label="platform.key">
          <el-tooltip :open-delay="800" placement="top-start">
            <span slot="content" style="max-width:200px;">{{ platform.label }}</span>
            <span class="tool-tip-content">{{ platform.label }}</span>
          </el-tooltip>
        </el-checkbox>
      </el-checkbox-group>
      <div class="popover-btns">
        <el-button class="ok" type="primary" @click="livePopoverConfirm">确定</el-button>
        <el-button class="cancel-btn-style" type="info" @click="cancelLiveSelected">重置</el-button>
      </div>
      <span slot="reference" :class="{ 'active-tab-name': activeTabs === '6' }" class="custom-tab-name">直播</span>
    </el-popover>
    <el-popover v-if="hasVideoAuth" v-model="videoPopoverVisible" width="170" popper-class="custom-tab-popover">
      <el-checkbox-group v-model="videoCheckedList" class="filter-checkbox-group" text-color="#fd3264" fill="#fd3264">
        <div class="el-checkbox">
          <span v-if="!videoCheckedList.length" class="check-box-btn active">
            <span class="check-box-style"/><span class="el-checkbox__label">全部</span>
          </span>
          <span v-else class="check-box-btn" @click.stop="cancelVideoSelected">
            <span class="check-box-style"/><span class="el-checkbox__label">全部</span>
          </span>
        </div>
        <el-checkbox v-for="platform in videoPlatformList" :key="platform.key" :label="platform.key">
          <el-tooltip :open-delay="800" placement="top-start">
            <span slot="content" style="max-width:200px;">{{ platform.label }}</span>
            <span class="tool-tip-content">{{ platform.label }}</span>
          </el-tooltip>
        </el-checkbox>
      </el-checkbox-group>
      <div class="popover-btns">
        <el-button class="ok" type="primary" @click="videoPopoverConfirm">确定</el-button>
        <el-button class="cancel-btn-style" type="info" @click="cancelVideoSelected">重置</el-button>
      </div>
      <span slot="reference" :class="{ 'active-tab-name': activeTabs === '5' }" class="custom-tab-name">更多</span>
    </el-popover>
  </div>
</template>

<script>
import { hasRouteAuth } from '@/utils/permission';
export default {
  name: 'ExtendTabs',
  props: {
    livePlatformList: {
      type: Array,
      default: () => []
    },
    videoPlatformList: {
      type: Array,
      default: () => []
    },
    activeTabs: {
      type: String | Number,
      default: ''
    }
  },
  data() {
    return {
      livePopoverVisible: false,
      videoPopoverVisible: false,
      liveCheckedList: [],
      videoCheckedList: []
    };
  },
  computed: {
    hasLiveAuth() {
      return hasRouteAuth('medium:platform:live');
    },
    hasVideoAuth() {
      return hasRouteAuth('medium:platform:video');
    }
  },
  methods: {
    cancelLiveSelected() {
      this.liveCheckedList = [];
      this.$emit('tabsChange', '6', '');
    },
    cancelVideoSelected() {
      this.videoCheckedList = [];
      this.$emit('tabsChange', '5', '');
    },
    livePopoverConfirm() {
      this.livePopoverVisible = false;
      // this.cancelVideoSelected();
      this.videoCheckedList = [];
      this.$emit('tabsChange', '6', this.liveCheckedList.join());
    },
    videoPopoverConfirm() {
      this.videoPopoverVisible = false;
      // this.cancelLiveSelected();
      this.liveCheckedList = [];
      this.$emit('tabsChange', '5', this.videoCheckedList.join());
    }
  }
};
</script>

<style lang="scss" scoped>
.custom-tab-name {
  display: inline-block;
  color: #333;
  font-size: 14px;
  height: 48px;
  line-height: 48px;
  margin: 0 16px;
  font-weight: 300;
  cursor: pointer;
}
.active-tab-name {
  color: #406EFF;
  font-weight: bold;
  border-bottom: 2px solid;
}
.check-box-btn {
  color: #666666;
  font-size: 14px;
  display: flex;
  cursor: pointer;
  align-items: center;
  line-height: 19px;
  white-space: nowrap;
  .check-box-style {
    display: inline-block;
    position: relative;
    border: 1px solid #DCDFE6;
    border-radius: 2px;
    -webkit-box-sizing: border-box;
    box-sizing: border-box;
    width: 14px;
    height: 14px;
    background-color: #FFFFFF;
    z-index: 1;
    -webkit-transition: border-color 0.25s cubic-bezier(0.71, -0.46, 0.29, 1.46), background-color 0.25s cubic-bezier(0.71, -0.46, 0.29, 1.46);
    transition: border-color 0.25s cubic-bezier(0.71, -0.46, 0.29, 1.46), background-color 0.25s cubic-bezier(0.71, -0.46, 0.29, 1.46);
  }
  &.active {
    color: #406EFF;;
    font-weight: bold;
    .check-box-style {
      background-color: #406EFF;;
      border: 1px solid #406EFF;;
      &::after {
        box-sizing: content-box;
        content: "";
        border: 1px solid #fff;
        border-left: 0;
        border-top: 0;
        height: 7px;
        left: 4px;
        position: absolute;
        top: 1px;
        transform: rotate(45deg);
        width: 3px;
        -webkit-transform-origin: center;
        transform-origin: center;
      }
    }
  }
}
.filter-checkbox-group {
  flex-wrap: wrap;
  display: flex;
  flex: 1;
  max-height: 280px;
  padding: 0 10px;
  @include scrollBar($width: 10px);
  .el-checkbox {
    flex-wrap: wrap;
    display: flex;
    align-items: center;
    margin-right: 0;
    margin-bottom: 12px;
  }
  .tool-tip-content {
    max-width: 100%;
    white-space: nowrap;
    text-overflow: ellipsis;
    overflow: hidden;
    display: block;
  }
  ::v-deep .el-checkbox__label {
    padding-left: 5px;
    width: 120px;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    color: #333;
  }
}
.popover-btns {
  display: flex;
  justify-content: center;
  padding-top: 10px;
  box-shadow: 2px -4px 5px 0 rgba(221,225,234,0.3);
  .ok {
    font-size: 14px;
    padding: 6px 14px;
    margin-right: 10px;
  }
  .cancel-btn-style {
    font-size: 14px;
    padding: 6px 14px;
  }
}
</style>
<style lang="scss">
.custom-tab-popover {
  top: 30px !important;
  padding-left: 0;
  padding-right: 0;
}
</style>
